package com.xhd.base.scheduler;

import com.xhd.base.log.Log;
import com.xhd.base.log.LogFactory;
import com.xhd.base.util.xBaseObj;
import com.xhd.config.ActionControl;
import com.xhd.config.SchedulerConfig;
import com.xhd.exception.XException;
import com.xhd.notice.NoticeFactory;
import com.xhd.notice.NoticeSender;
import com.xhd.pool.ResourcePool;
import com.xhd.server.ProcessHandle;
import com.xhd.server.ProcessHandleMgr;
import com.xhd.server.ServerConfig;
import com.xhd.servlet.ClientAction;


public class AsyncProcessThread extends Thread
	{
	  protected boolean stop = false;
	  private boolean jm177 = false;
	  private xBaseObj jm114 = null;
	  private static int jm178 = 1;
	  private static final Log jm9;
	  static Class jm10;
	  static Class jm17;

	  static
	  {
	    Class tmp7_4 = jm10;
	    if (tmp7_4 == null)
	    {
	      
	      try
	      {
	        AsyncProcessThread.jm10 = Class.forName("com.sinocc.base.scheduler.AsyncProcessThread");
	      }
	      catch (ClassNotFoundException localClassNotFoundException)
	      {
	        throw new NoClassDefFoundError(localClassNotFoundException.getMessage());
	      }
	    }
	    jm9 = LogFactory.getLog(tmp7_4);
	  }

	  public AsyncProcessThread()
	  {
	    setName("AsynchronyProcessThread-" + jm178);
	    jm178 += 1;
	  }

	  public void setBizObj(xBaseObj paramxBaseObj)
	  {
	    this.jm114 = paramxBaseObj;
	    synchronized (this)
	    {
	      if (!(this.jm177))
	      {
	        this.jm177 = true;
	        start();
	      }
	      else
	      {
	        super.notify();
	      }
	    }
	  }

	  public xBaseObj getBizObj()
	  {
	    return this.jm114;
	  }

	  public void run()
	  {
	    ClientAction localClientAction = new ClientAction(2);
	    localClientAction.setServiceName("CPCAsyncProcessThread");
	    localClientAction.setClientIP("127.0.0.1");
	    ActionControl localActionControl = ActionControl.getInstance();
	    Object localObject1 = null;
	    while (!(this.stop))
	    {
	      if (this.stop)
	        return;
	      if (this.jm114 != null)
	      {
	        try
	        {
	          localObject1 = null;
	          localClientAction.setMethodName(this.jm114.getClientAction().getFullName());
	          ProcessHandle localProcessHandle = ProcessHandleMgr.openHandle(localClientAction, this.jm114);
	          localObject1 = localActionControl.processTransaction(this.jm114, this.jm114.getClientAction(), localProcessHandle);
	          if (localObject1 != null)
	            jm9.error(localClientAction.getFullName(), (Throwable)localObject1);
	        }
	        catch (Throwable localThrowable1)
	        {
	          localObject1 = localThrowable1;
	          jm9.error(localClientAction.getFullName(), localThrowable1);
	        }
	        finally
	        {
	          ProcessHandleMgr.closeHandle();
	          AsyncProcessMgr.getInstance().processFinish(this);
	        }
	        try
	        {
	          jm176((Throwable)localObject1);
	        }
	        catch (Throwable localThrowable2)
	        {
	        }
	        this.jm114 = null;
	      }
	      try
	      {
	        synchronized (this)
	        {
	          super.wait();
	        }
	      }
	      catch (InterruptedException localInterruptedException)
	      {
	        localInterruptedException.printStackTrace();
	      }
	    }
	  }

	  private void jm176(Throwable paramThrowable)
	  {
	    int i = SchedulerConfig.getInstance().getAsyncNotice(this.jm114.getClientAction());
	    if (i == 0)
	      return;
	    boolean bool = false;
	    Class tmp26_23 = jm17;
	    if (tmp26_23 == null)
	    {
	     
	      try
	      {
	       AsyncProcessThread.jm17 = Class.forName("com.sinocc.base.scheduler.AsyncProcessBizObj");
	      }
	      catch (ClassNotFoundException localClassNotFoundException)
	      {
	        throw new NoClassDefFoundError(localClassNotFoundException.getMessage());
	      }
	    }
	    if (tmp26_23.isInstance(this.jm114))
	    {
	      AsyncProcessBizObj    localObject = (AsyncProcessBizObj)this.jm114;
	      bool = ((AsyncProcessBizObj)localObject).onAsyncProcessFinish(paramThrowable);
	    }
	    if (bool)
	      return;
	    Object localObject = NoticeFactory.getSender(i);
	    if (localObject == null)
	      return;
	    String str1 = "";
	    int j = this.jm114.getVaultInfo().getLangId();
	    ResourcePool localResourcePool = ServerConfig.resourcePool;
	    ClientAction localClientAction = this.jm114.getClientAction();
	    if (localClientAction == null)
	      return;
	    String str2 = null;
	    if (paramThrowable != null)
	      if (paramThrowable instanceof XException)
	        str2 = ((XException)paramThrowable).getMessage(j);
	      else
	        str2 = paramThrowable.getMessage();
	    if (str2 == null)
	      str1 = localResourcePool.getString(j, 900001, localResourcePool.getClassName(j, localClientAction.getServiceName()), localResourcePool.getActionName(j, localClientAction.getMethodName()));
	    else
	      str1 = localResourcePool.getString(j, 900002, localResourcePool.getClassName(j, localClientAction.getServiceName()), localResourcePool.getActionName(j, localClientAction.getMethodName()), str2);
	    ((NoticeSender)localObject).sendNoticeTo(this.jm114.getSession().getId(), this.jm114.getUserInfo().getSysUserId(), str1, null);
	  }
}
